#pragma once

#include <vector>
#include <queue>
#include "Semaphore.h"
#include "Task.h"

class WorkerThread;

class ThreadPool {
public:
    ThreadPool();
    ~ThreadPool();

    bool Open(int threadNum);
    void Shutdown();
    bool PostTask(Task* task);
    Task* GetTask();

protected:
    virtual WorkerThread* CreateWorkThread();

private:
    std::vector<WorkerThread*> m_ThreadList;
    std::queue<Task*> m_TaskQueue;

    Condition m_Cond;
    Mutex m_Mutex;
    bool m_bRun;
};
